<?php

class CustomRegisterForm extends sfGuardRegisterForm
{

  public function configure()
  {
    $this->widgetSchema->setNameFormat('user[%s]');

    $this->widgetSchema->getFormFormatter()->setTranslationCatalogue('form');

    $this->widgetSchema->setLabels(array(
        'first_name' => 'First name',
        'last_name' => 'Last name',
        'username' => 'Username',
        'email_address' => 'Email',
        'password' => 'Password',
        'password_again' => 'Confirmation'
    ));

    $this->validatorSchema['first_name']->setOption('required', true);
    $this->validatorSchema['last_name']->setOption('required', true);

    $this->validatorSchema['username'] = new sfValidatorAnd(array(
                $this->validatorSchema['username'],
                new sfValidatorString(
                        array('min_length' => 4, 'max_length' => 20),
                        array('min_length' => 'Username too short, minimum %min_length% characters', 'max_length' => 'Username too large, maximum %max_length% characters')
                ),
                new sfValidatorDoctrineUnique(array('model' => 'sfGuardUser', 'column' => 'username'), array('invalid' => 'Username already used'))
            ));

    $this->validatorSchema['email_address'] = new sfValidatorAnd(array(
                $this->validatorSchema['email_address'],
                new sfValidatorEmail(array(), array('invalid' => 'Invalid email address')),
                new sfValidatorDoctrineUnique(array('model' => 'sfGuardUser', 'column' => 'email_address'), array('invalid' => 'Email address already used'))
            ));

    $this->validatorSchema['password'] = new sfValidatorAnd(array(
                new sfValidatorString(
                        array('min_length' => 7),
                        array('min_length' => 'Password too short, minimum %min_length% characters')
                )
            ));

    $this->validatorSchema['password_again'] = new sfValidatorAnd(array(
                new sfValidatorString(
                        array('min_length' => 7),
                        array('min_length' => 'Password too short, minimum %min_length% characters')
                )
            ));
  }

}